package com.buobao.oa.controller;

import com.buobao.oa.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "ForwardServlet",urlPatterns = "/forward/*")
public class ForwardServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        if (session==null) {
            resp.sendRedirect("/timeover.html");
            return;
        }
        User user = (User) session.getAttribute("login_user");
        if (user!=null) {
            String uri = req.getRequestURI();
            String suburi = uri.substring(1);
            String path = suburi.substring(suburi.indexOf("/"));
            req.getRequestDispatcher(path+".ftl").forward(req,resp);
        } else {
            resp.sendRedirect("/timeover.html");
        }
    }
}
